

class Shotcuts:
    def __init__(self):
        self.shotcuts = []
        self.load()
        
    def add(self, sc):
        if sc in self.shotcuts:
            return False
        else:
            self.shotcuts.append(sc)
            return True
    
    def getkey(self, shotcutname):
        for i, sc in enumerate(self.shotcuts):
            if(shotcutname == sc): return i
        return -1;
    
    def getname(self, key):
        if key>=0 and key<len(self.shotcuts):
            return self.shotcuts[key]
        else:
            return None
    
    def printall(self):
        for i in range(0, len(self.shotcuts)):
            print "%s: %s" %(i, self.shotcuts[i])
            
    def load(self):
        scfile = open('data/shotcuts.dat','r')
        for line in scfile.readlines():
            line = line.strip()
            if len(line): self.shotcuts.append(line)
            
    def save(self):
        open('data/shotcuts.dat','w').write("\n".join(self.shotcuts))


# for test
if __name__ == '__main__':
    sc = Shotcuts()
    sc.printall()
    print sc.getname(-1)
    print sc.getname(0)
    print sc.getname(1)
    print sc.getname(10)
    print sc.getkey('lunch')
    print sc.getkey('hello')